﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Instruments
{
    public class Source:Visa
    {
        public static string _sType = "xxxx";
        public List<string> _ListInitCmd;
        protected string _szCmd;
        protected string _szRet;
        public string _szErrCmd;
        public string _szErrRet;
        public string _szType;

        public double _dVolt;
        public double _dCurr;
        public double _dPower;

        public Source(string szInsID):base(szInsID)
        {
            _ListInitCmd = new List<string>();
            _szType = _sType;
        }

        public virtual bool Init()
        {
            bool bRet = this.QueryType().Contains(_sType);
            if(bRet)
            {
                for (int i = 0; i < _ListInitCmd.Count; i++)
                {
                    _szCmd = _ListInitCmd[i];
                    this.Write(_szCmd);
                }
            }
            this.Set_VFC("0", "0");
            return bRet;
        }

        public virtual void Set_VFC(string Volt, string FC)
        {
        }

        public virtual double Meas_Volt()
        {
            _dVolt = 0.0;
            this.Clean();

            _szRet = this.Query(_szCmd);
            double.TryParse(_szRet, out _dVolt);
            return _dVolt;
        }

        public virtual double Meas_Curr()
        {
            _dCurr = 0.0;
            this.Clean();

            _szRet = this.Query(_szCmd);
            double.TryParse(_szRet, out _dCurr);
            return _dCurr;
        }

        public virtual double Meas_Power()
        {
            _dPower = 0.0;
            this.Clean();

            _szRet = this.Query(_szCmd);
            double.TryParse(_szRet, out _dPower);
            return _dPower;
        }

        public virtual void ONorOFF(bool NF)
        {
        }

        public virtual bool QueryState()
        {
            return _szErrRet.Equals(this.Query(_szErrCmd));
        }
    }
}
